#!/usr/bin/env python
#
# Copyright 2009 Liu, Xiaokang <4341322@gmail.com>
# Blog <http://www.ioio.name/>
#

from google.appengine.api import taskqueue
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import urlfetch

from handlestory import handle_result

class Test(webapp.RequestHandler):
    def get(self):
        taskqueue.add(url='/work', params={'url': 'http://www.nuoqiu.com/static/5630/1216064.html'})
        self.response.out.write('OK')
    
class StoryWork(webapp.RequestHandler):
  def get(self):
    #self.response.out.write('Are Your Site is uptime now?')
    url = self.request.get('url')
    self._fetch(handle_result,url)
    
  def _fetch(self,callback,url):
    rpc = urlfetch.create_rpc(deadline=10)
    rpc.callback = callback(rpc)
    urlfetch.make_fetch_call(rpc, url)
    
      
application = webapp.WSGIApplication([
  ('/',Test),
  ('/work', StoryWork)
], debug=True)

def main():
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
  main()
